|
Cytosim
PI
Cytoskeleton Simulator
|
Array<typename VAL> stores instatiations of the class VAL. VAL need to have a public constructor without argument.
This class resembles std::vector<VAL>, with similar functionalities. Many functions of std::vector are missing, and some are new: remove(), sort() and mix().
Some functions:
New memory is allocated if necessary by allocate(), and the values from the old array are copied to the new memory space.
Allocation when it is done exceeds what is necessary by a bit, to ensure that allocation only occurs from time-to-time, even if one adds objects one by one to the array.
Destruction of objects is not handled by the Array.
Public Types | |
| typedef unsigned | index_type |
| typedef for type used as array index | |
| typedef VAL | value_type |
| typedef for the template argument | |
| typedef VAL * | iterator |
| iterator class type | |
Public Member Functions | |
| Array () | |
| Default creator without allocation. | |
| Array (unsigned s, unsigned k) | |
Allocate size s, and set chunk size to chk | |
| Array (Array< VAL > const &o) | |
| Copy constructor. | |
| virtual | ~Array () |
| Destructor. | |
| Array & | operator= (Array< VAL > const &o) |
| Assignment operator. | |
| unsigned | size () const |
| Number of objects. | |
| bool | empty () const |
| true if this Array holds no value | |
| unsigned | capacity () const |
| Currently allocated size. | |
| VAL * | addr () const |
| Address of the underlying C-array. | |
| iterator | begin () const |
| pointer to first element | |
| iterator | end () const |
| pointer to a position just past the last element | |
| VAL & | at (const index_type ii) const |
| reference to Object at index ii (val_[ii]) | |
| VAL & | operator[] (const index_type ii) const |
| reference to Object at index ii (val_[ii]) | |
| void | reallocate (const unsigned alc_new) |
Allocate to hold s objects: valid indices are 0 <= indx < max. | |
| unsigned | allocate (const unsigned s) |
Allocate to hold at least s objects: valid indices are 0 <= indx < max. | |
| int | allocate_zero (const unsigned size, VAL const &zero) |
Allocate and set new values to zero | |
| void | truncate (const unsigned size) |
| truncate Array to a smaller size | |
| void | resize (const unsigned size) |
Set the size of this Array to size (allocate or truncate if necessary) | |
| void | deallocate () |
| Release occupied memory. | |
| void | clear () |
| Set the number of objects to zero. | |
| void | destroy () |
| Delete all values as if they were pointers to Object. | |
| void | zero (VAL const &zero) |
Set all values to zero | |
| VAL & | new_val () |
| Increment the size of the array, and return new value at end of it. | |
| void | push_back (const VAL np) |
Add np at the end of this Array. | |
| void | append (const Array< VAL > array) |
Add the elements of array at the end of this Array. | |
| int | find (const VAL obj) const |
Return index of obj, or -1 if not found in the list (slow scan search) | |
| bool | replace (VAL const &old_value, VAL const &new_value) |
Replace old_value by new_value, or return false if old_value is not found. | |
| void | push_pack (const VAL np, const VAL &zero) |
Add np replacing a position where val_[ii]==zero, or at the end of this Array. | |
| unsigned | count (VAL const &zero=0) const |
Number of times the value zero occurs in the array. | |
| void | remove (VAL const &zero) |
Remove all entries which are equal to zero, and pack array. | |
| void | sort (int(*comp)(const void *, const void *)) |
| sort array using standard C-library function qsort() | |
| VAL & | pick_one (Random &rng) |
| Swap two random values in the array. | |
| void | turn () |
| Move the last Object on top, push all other values down by one slot. | |
| void | permute (Random &rng) |
| Swap two random values in the array. | |
| void | mix (Random &rng) |
| Randomly permutes all objects in the array. More... | |
|
inline |
This produces uniform shuffling in linear time. see Knuth's The Art of Programming, Vol 2 chp. 3.4.2